package com.woniu.mealsService.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author jiang
 */
@Configuration
@ConfigurationProperties(prefix = "alipay.config")
@Data
public class AliPayConfig {
    private String serverUrl;
    private String appId;
    private String privateKey;
    private String alipayPublicKey;
    private String notify_url;
    private String return_url;
    private String signType;
    private String charset;
    private String format;
    @Bean
    public AlipayClient alipayClient() throws  Exception{
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setAppId(appId);
        alipayConfig.setServerUrl(serverUrl);
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setFormat(format);
        alipayConfig.setSignType(signType);
        return new DefaultAlipayClient(alipayConfig);
    }
}
